silence MSVC with definitions and options (#859)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sat, 26 Feb 2022 00:03:10 +0000 (17:03 -0700)
committerGitHub <noreply@github.com>
Sat, 26 Feb 2022 00:03:10 +0000 (17:03 -0700)
* deal with MSVC CRT security warnings in a consistent manner.

* correct cmake targets

* turn off some MSVC warnings for shapelib, zlib with cmake.

* fix msvc C4100 warning handling.

There was interference between our attempt to turn off the warning
with -wd4100 and win32-msvc mkspec changing the level of this
warning with -w34100.

CMakeLists.txt
GPSBabel.pro
defs.h
shapelib.cmake
zlib.cmake

index d0acd5774546273c009d5da89fe14f5605b1abf8..6f696383a987cc34a75b5bc6252e4a6a7b282fb2 100644 (file)
@@ -352,7 +352,8 @@ if(WIN32)
 endif()
 
 if(MSVC)
-  target_compile_definitions(gpsbabel PRIVATE _CRT_SECURE_NO_DEPRECATE)
+  target_compile_definitions(gpsbabel PRIVATE _CRT_SECURE_NO_WARNINGS)
+  target_compile_definitions(gpsbabel PRIVATE _CRT_NONSTDC_NO_WARNINGS)
   target_compile_options(gpsbabel PRIVATE /MP -wd4100 -wd4267)
 endif()
 
index 47b2be048ee898941cbcdeda877c1941231547e3..c852797feac6bc7268873cc019af2dc44200e94a 100644 (file)
@@ -338,9 +338,20 @@ win32 {
 }
 
 win32-msvc* {
-  DEFINES += _CRT_SECURE_NO_DEPRECATE
-  QMAKE_CFLAGS += /MP -wd4100 -wd4267
-  QMAKE_CXXFLAGS += /MP -wd4100 -wd4267
+  DEFINES += _CRT_SECURE_NO_WARNINGS
+  DEFINES += _CRT_NONSTDC_NO_WARNINGS
+  QMAKE_CFLAGS += /MP -wd4267
+  QMAKE_CXXFLAGS += /MP -wd4267
+  # The -wd (disable warning) and -w3 (change warning to level 3) options are exclusive.
+  # The win32-msvc makespec uses -w34100, which can interfer with -wd4100.
+  # Their are two qmake settings for warnings in CONFIG: warn_on and warn_off.
+  # This results in the warning showing with msbuild, but not with nmake, even if
+  # -wd4100 is included in QMAKE_CFLAGS and QMAKE_CXXFLAGS.
+  # Override win32-msvc, leaving these warnings at their default of level 4, which
+  # will not show up because we run at level 3.
+  # shapelib/shpopen.c can cause a C4100 error.
+  QMAKE_CFLAGS_WARN_ON -= -w34100
+  QMAKE_CXXFLAGS_WARN_ON -= -w34100
 }
 
 include(shapelib.pri)
diff --git a/defs.h b/defs.h
index c093020de089eaf7a0155faf79d2e9ccc4547cad..b08b45f8aa3fcfcf85d092c21d86315d6ff11778 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -126,19 +126,6 @@ constexpr double KNOTS_TO_MPS(double a)  {return a * kMPSPerKnot;}
 #define CENTI_TO_MICRO(t) ((t) * 10000) /* Centiseconds to Microseconds */
 #define MICRO_TO_CENTI(t) ((t) / 10000) /* Centiseconds to Microseconds */
 
-#if __WIN32__
-#  ifndef fileno
-#    define fileno _fileno
-#  endif
-#  define strdup _strdup
-#endif
-
-#if __WIN32__
-#if !defined _CRT_SECURE_NO_DEPRECATE
-#  define _CRT_SECURE_NO_DEPRECATE 1
-#endif
-#endif
-
 /* Pathname separator character */
 #if __WIN32__
 #  define GB_PATHSEP '\\'
index 0d53c71ac55786b12044db9e586b35470440383f..d52f28e3c6514f3279be138a029d516fe4623e05 100644 (file)
@@ -19,6 +19,11 @@ else()
     # note gpsbabel has conditional code include "shapelib/shapefil.h",
     # so it doesn't actually rely on the include directory being PUBLIC/INTERFACE
     target_include_directories(shp PUBLIC shape)
+    if(MSVC)
+      target_compile_definitions(shp PRIVATE _CRT_SECURE_NO_WARNINGS)
+      target_compile_definitions(shp PRIVATE _CRT_NONSTDC_NO_WARNINGS)
+      target_compile_options(shp PRIVATE /MP -wd4100 -wd4267)
+    endif()
     list(APPEND LIBS shp)
   elseif(GPSBABEL_WITH_SHAPELIB STREQUAL "custom")
     message(STATUS "shapelib is enabled but but must be manually configured.")
index 950b57833661fea702c47f4788b04ca09f30537d..6f1fe6fda5b9a26f2d30f857142b60bce66541dd 100644 (file)
@@ -54,6 +54,11 @@ else()
         target_compile_definitions(z PRIVATE HAVE_STDARG_H)
       endif()
     endif()
+    if(MSVC)
+      target_compile_definitions(z PRIVATE _CRT_SECURE_NO_WARNINGS)
+      target_compile_definitions(z PRIVATE _CRT_NONSTDC_NO_WARNINGS)
+      target_compile_options(z PRIVATE /MP -wd4100 -wd4267)
+    endif()
     target_include_directories(z PUBLIC zlib)
     list(APPEND LIBS z)
   elseif(GPSBABEL_WITH_ZLIB STREQUAL "custom")